import random


class Person:
    def __init__(self, name):
        self.name = name
        self.life = 100

    def __str__(self):
        return '{}当前的生命值为：{} '.format(self.name, self.life)

    def leftValue(self, life, damage):
        if life < damage:
            life = 0
        else:
            life = life - damage
        return life

class Hero(Person):
    def fire(self, p):
        # 添加 命中率
        hit=random.randint(1,100)
        if hit>20: #命中率80%
        #     判断当前射击是否已经死亡
          if p.life==0:
              print("{}都死亡了，就不要鞭尸了".format(p.name))
          else:
              damage = random.randint(20,50)
              print("{}向{}开枪，造成了{}伤害".format(self.name, p.name, damage))
              p.life = self.leftValue(p.life, damage)
        else:
            print("枪法真臭，这是个臭籽，没有打到恐怖份子")
    def __str__(self):
        status = ""
        if self.life == 100:
            status = "无伤"
        elif self.life >= 70:
            status = "轻伤"
        elif self.life >= 1:
            status = "重伤"
        else:
            status = "挂了"
        return "{}当前状态是{}".format(self.name, status)

class Is(Person):
    def fire(self, p):
        damage = 10
        print("{}向{}开枪，造成了{}伤害".format(self.name, p.name, damage))
        p.life = self.leftValue(p.life, damage)
        # if p.life < damage:
        #     p.life = 0
        # else:
        #     p.life = p.life - damage


def mian():
    h = Hero("【英雄】")
    print(h)
    is1 = Is("【匪徒1】")
    is2 = Is("【匪徒2】")
    is3 = Is("【匪徒3】")
    print(is1)
    while True:
        # 产生1-3的随机数
        x = random.randint(1, 3)
        if x == 1:
            h.fire(is1)
        elif x == 2:
            h.fire(is2)
        else:
            h.fire(is3)
        is1.fire(h)
        is2.fire(h)
        is3.fire(h)
        print(is1)
        print(is2)
        print(is3)
        print()
        # 设置结束条件
        if h.life <= 0:
            print(f"{h.name}死亡，枪战结束")
            break
        if is1.life <= 0 and is2.life <= 0 and is3.life <= 0:
            print("所有恐怖份子全部死亡，枪战结束")
            break
mian()